import setting from '../config/setting.js'
import helper from '../helper'
import store from '../store'
import local from './local'

export default {
  login (data) {
    store.state.user.user = data
    local.setItem(setting.userToken, data)
  },
  authenticated () {
    return !helper.isEmpty(this.getToken())
  },
  getToken () {
    let user = local.getItem(setting.userToken)
    if (user) {
      store.state.user.user = user
    }
    return store.state.user.user
  },
  logout () {
    store.state.user.user = {}
    local.setItem(setting.userToken, {})
  }
}
